package com.purvar.controller;

import com.google.common.collect.Lists;
import org.flowable.ui.common.model.UserRepresentation;
import org.flowable.ui.common.rest.idm.CurrentUserProvider;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collection;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/my-app")
public class MyRemoteAccountController {
    protected final Collection<CurrentUserProvider> currentUserProviders;

    public MyRemoteAccountController(ObjectProvider<CurrentUserProvider> currentUserProviders) {
        this.currentUserProviders = currentUserProviders.orderedStream().collect(Collectors.toList());
    }


    /**
     * GET /rest/account -> get the current user.
     */
    @GetMapping(value = "/rest/account", produces = "application/json")
    public UserRepresentation getAccount(Authentication authentication) {
        UserRepresentation userRepresentation = new UserRepresentation();
        userRepresentation.setId("lemon");
        userRepresentation.setFirstName("lemon");
        userRepresentation.setPrivileges(Lists.newArrayList("flowable-idm","flowable-modeler","flowable-task"));
        return userRepresentation;
    }

}
